package com.vertexnet.realestatenet.model.bean;

// Generated May 22, 2012 8:11:57 AM by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.CascadeType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * PaymentPlan generated by hbm2java
 */
@Entity
@Table(name = "payment_plan", catalog = "real_estate_net")
public class PaymentPlan implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer planId;
	private Layout layout;
	private String planName;
	private Set<Installment> installments = new HashSet<Installment>(0);
	private Set<Site> sites = new HashSet<Site>(0);

	public PaymentPlan() {
	}

	public PaymentPlan(Layout layout, String planName) {
		this.layout = layout;
		this.planName = planName;
	}

	public PaymentPlan(Layout layout, String planName, Set<Installment> installments, Set<Site> sites) {
		this.layout = layout;
		this.planName = planName;
		this.installments = installments;
		this.sites = sites;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "plan_id", unique = true, nullable = false)
	public Integer getPlanId() {
		return this.planId;
	}

	public void setPlanId(Integer planId) {
		this.planId = planId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "layout_id", nullable = false)
	public Layout getLayout() {
		return this.layout;
	}

	public void setLayout(Layout layout) {
		this.layout = layout;
	}

	@Column(name = "plan_name", nullable = false, length = 25)
	public String getPlanName() {
		return this.planName;
	}

	public void setPlanName(String planName) {
		this.planName = planName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "paymentPlan", orphanRemoval=true)
	@NotFound(action = NotFoundAction.IGNORE)
	public Set<Installment> getInstallments() {
		return this.installments;
	}

	public void setInstallments(Set<Installment> installments) {
		this.installments = installments;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "paymentPlan")
	@NotFound(action = NotFoundAction.IGNORE)
	public Set<Site> getSites() {
		return this.sites;
	}

	public void setSites(Set<Site> sites) {
		this.sites = sites;
	}

	@Override
	public String toString() {
		return planName;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof PaymentPlan) {
			PaymentPlan paymentPlan = (PaymentPlan) obj;
			return new EqualsBuilder()
			.append(this.getPlanId(),paymentPlan.getPlanId())
			.append(this.getLayout(),paymentPlan.getLayout())
			.append(this.getPlanName(),paymentPlan.getPlanName())
			.isEquals();
		}
		return false;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
		.append(this.planId)
		.append(this.layout)
		.append(this.planName)
		.toHashCode();
	}
}
